package org.chen.common.constant;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.chen.common.exception.ServiceException;

@Getter
@AllArgsConstructor
public enum ArticleStatusEnum {
    PENDING(0, "未处理"),
    PROCESSING(1, "处理中"),
    COMPLETED(2, "已完成"),
    FAILED(3, "失败");
    
    private final Integer code;
    private final String desc;
    
    public static String getDesc(Integer code) {
        for (ArticleStatusEnum status : values()) {
            if (status.getCode().equals(code)) {
                return status.getDesc();
            }
        }
        return "";
    }
    
    public static ArticleStatusEnum getByCode(Integer code) {
        for (ArticleStatusEnum status : values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        throw new ServiceException("未知的文章状态: " + code);
    }
    
    public static boolean isValid(Integer code) {
        for (ArticleStatusEnum status : values()) {
            if (status.getCode().equals(code)) {
                return true;
            }
        }
        return false;
    }
}